import {Trigger} from "solar/w3ts/handles/trigger";
import DataBase from "../../solar/common/DataBase";


export default class FailState {


    constructor() {
        let trigger1 = new Trigger()
        trigger1.registerEnterRect(gg_rct_p1_sb_12);
        trigger1.addAction(() => {
            this.action(0)
        })
        let trigger2 = new Trigger()
        trigger2.registerEnterRect(gg_rct_p2_sb_12);
        trigger2.addAction(() => {
            this.action(1)
        })
        let trigger3 = new Trigger()
        trigger3.registerEnterRect(gg_rct_p3_sb_12);
        trigger3.addAction(() => {
            this.action(2)
        })
        let trigger4 = new Trigger()
        trigger4.registerEnterRect(gg_rct_p4_sb_12);
        trigger4.addAction(() => {
            this.action(3)
        })

    }

    action(index: number) {
        if (!IsUnitEnemy(GetTriggerUnit(), Player(0))) {
            return
        }
        let solarData = DataBase.getPlayerSolarData(Player(index));
        if (!solarData.FailState_LouGuai_Count) {
            solarData.FailState_LouGuai_Count = 0;
        }
        solarData.FailState_LouGuai_Count++;
        ExplodeUnitBJ(GetTriggerUnit())
        if (solarData.FailState_LouGuai_Count > 30) {
            CustomDefeatBJ(Player(index), "失败了！");
        }
    }


}

